package soundsystem;

import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * author: xl
 * time: 2018/5/7 9:46
 * description:通过切面编程，记录磁盘播放记录
 **/

@Aspect
//@Component
public class TrackCounter {

    public TrackCounter(){
    }


     private Map<Integer,Integer> map = new HashMap<>();


//     @Pointcut("execution(* soundsystem.CompactDisc.playNumber(..))&& args(trackNumber)")
//     public void trackPlay(int trackNumber){
//         int number = getPlayNumber(trackNumber);
//         map.put(trackNumber,number+1);
//     }


    @Around("execution(* soundsystem.CompactDisc.playNumber(..))&& args(trackNumber)")
    public void trackPlay(int trackNumber){
        System.out.println("pointCut");
        int number = getPlayNumber(trackNumber);
        map.put(trackNumber,number+1);
    }



//    @Before("trackPlay(trackNumber)")
//    public void beforeTest(int trackNumber){
//        System.out.println("beforeTest trackNumber:"+trackNumber);
//    }
//
//    @After("trackPlay(trackNumber)")
//    public void afterTest(int trackNumber){
//        System.out.println("afterTest trackNumber:"+trackNumber);
//    }



     public int getPlayNumber(int trackNumber){
         return map.containsKey(trackNumber)?map.get(trackNumber):0;
     }



}
